﻿<u:HeaderedToolItem x:Class="WickedFlame.VecDraw.Plugins.LayerDisplay"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:cmds="clr-namespace:WickedFlame.VecDraw.VecApp"
    xmlns:ctrl="clr-namespace:WickedFlame.VecDraw.Base.Controls;assembly=VecDraw.Base"
    xmlns:u="clr-namespace:WickedFlame.Util.Controls;assembly=VecDraw.Util"
    xmlns:local="clr-namespace:WickedFlame.VecDraw.Plugins"
    xmlns:c="clr-namespace:WickedFlame.Core.Layers;assembly=VecDraw.Core"
    Height="Auto" Title="Layers"  Foreground="WhiteSmoke" FontSize="10" Icon="/VecDraw.Resources;component/Images/VecDraw.Icon.Layers.png" SizeChanged="ContentDocument_SizeChanged" >

    <Control.CommandBindings>
        <CommandBinding Command="cmds:HistoryCommands.CombineLayersCommand" CanExecute="CommandCanExecute" Executed="CommandExecuted" />
        <CommandBinding Command="cmds:HistoryCommands.LayerDownCommand" CanExecute="CommandCanExecute" Executed="CommandExecuted" />
        <CommandBinding Command="cmds:HistoryCommands.LayerUpCommand" CanExecute="CommandCanExecute" Executed="CommandExecuted" />
        <CommandBinding Command="cmds:HistoryCommands.AddCommand" CanExecute="CommandCanExecute" Executed="CommandExecuted" />
        <CommandBinding Command="cmds:HistoryCommands.DeleteCommand" CanExecute="CommandCanExecute" Executed="CommandExecuted" />
    </Control.CommandBindings>
    
    <Control.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="../Resources/ControlTemplates.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Control.Resources>
   
    <Grid >
        <Grid.Resources>
            <Image x:Key="Combinelayers" Source="/VecDraw.Resources;component/Images/VecDraw.Icon.CombineLayers.png" Height="16" Width="16" />
            <Image x:Key="CombinelayersDisabled" Source="/VecDraw.Resources;component/Images/VecDraw.Icon.CombineLayersDisabled.png" Height="16" Width="16" />
            <Image x:Key="ArrowDown" Source="/VecDraw.Resources;component/Images/VecDraw.Icon.ArrowDown.png" Height="16" Width="16" />
            <Image x:Key="ArrowDownDisabled" Source="/VecDraw.Resources;component/Images/VecDraw.Icon.ArrowDownDisabled.png" Height="16" Width="16" />
            <Image x:Key="ArrowUp" Source="/VecDraw.Resources;component/Images/VecDraw.Icon.ArrowUp.png" Height="16" Width="16" />
            <Image x:Key="ArrowUpDisabled" Source="/VecDraw.Resources;component/Images/VecDraw.Icon.ArrowUpDisabled.png" Height="16" Width="16" />
            <Image x:Key="Add" Source="/VecDraw.Resources;component/Images/VecDraw.Icon.Add.png" Height="16" Width="16" />
            <Image x:Key="AddDisabled" Source="/VecDraw.Resources;component/Images/VecDraw.Icon.AddDisabled.png" Height="16" Width="16" />
            <Image x:Key="Delete" Source="/VecDraw.Resources;component/Images/VecDraw.Icon.Close.png" Height="16" Width="16" />
            <Image x:Key="DeleteDisabled" Source="/VecDraw.Resources;component/Images/VecDraw.Icon.CloseDisabled.png" Height="16" Width="16" />

            <Style x:Key="{x:Type ListBoxItem}" TargetType="ListBoxItem">
                <Setter Property="SnapsToDevicePixels" Value="true"/>
                <Setter Property="OverridesDefaultStyle" Value="true"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="ListBoxItem">
                            <Border Name="Border" Padding="2" SnapsToDevicePixels="true">
                                <u:LayerButton DataContext="{Binding .}" Layer="{Binding .}"/>
                            </Border>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsMouseOver" Value="true">
                                    <Setter TargetName="Border" Property="Background" Value="#20FFFFFF" />
                                </Trigger>
                                <Trigger Property="IsSelected" Value="true">
                                    <Setter TargetName="Border" Property="Background" Value="#50FFFFFF"/>
                                </Trigger>
                                <Trigger Property="IsEnabled" Value="false">
                                    <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

        </Grid.Resources>
        
        <DockPanel LastChildFill="True">
            
            <StackPanel DockPanel.Dock="Bottom" Height="25" Orientation="Horizontal" >
                
                <ctrl:ImageButton Icon="{StaticResource Add}" Command="cmds:HistoryCommands.AddCommand" Name="btnAddLayer"  Width="21"  Margin="2,2,0,2"/>
                <ctrl:ImageButton Icon="{StaticResource Delete}" Command="cmds:HistoryCommands.DeleteCommand" Name="btnDeleteLayer"  Width="21" Margin="0,2,0,2"/>
                <ctrl:ImageButton Icon="{StaticResource ArrowUp}" Command="cmds:HistoryCommands.LayerUpCommand" Name="btnLayerUp"  Width="21" Margin="0,2,0,2"/>
                <ctrl:ImageButton Icon="{StaticResource ArrowDown}" Command="cmds:HistoryCommands.LayerDownCommand" Name="btnLayerDown"  Width="21" Margin="0,2,0,2"/>
                <ctrl:ImageButton Icon="{StaticResource Combinelayers}"  Command="cmds:HistoryCommands.CombineLayersCommand" Name="btnCombineLayers"  Width="21" Margin="0,2,0,2"/>

            </StackPanel>
            
            <Grid DockPanel.Dock="Top">
                <Border BorderBrush="#50FFFFFF" BorderThickness="0,0,0,1" Margin="5,0,5,0">
                    <!--<ScrollViewer VerticalScrollBarVisibility="Auto" >
                        <StackPanel Name="layerPanel" />
                    </ScrollViewer>-->
                </Border>

                <ListBox SnapsToDevicePixels="True" ItemsSource="{Binding Layers}" SelectedIndex="{Binding SelectedLayerIndex}" MaxHeight="150" MinHeight="60" Background="Transparent" BorderBrush="Transparent" />
                
            </Grid>
        </DockPanel>
    </Grid>
</u:HeaderedToolItem>
